package blackberry.util.assert;

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

class DjAssertionFailedErrorScreen extends PopupScreen {

	public DjAssertionFailedErrorScreen(String message) {
		super(new VerticalFieldManager());
		setBackground(BackgroundFactory.createSolidBackground(Color.RED));
		add(new LabelField(message));
	}

	public void pushErrorScreen() {
		synchronized (UiApplication.getEventLock()) {
			UiApplication.getUiApplication().pushGlobalScreen(this,
					Integer.MIN_VALUE, UiEngine.GLOBAL_SHOW_LOWER);
		}
	}

	protected boolean keyDown(int keycode, int time) {
		if (Keypad.key(keycode) == Characters.ESCAPE)
			popErrorScreen();
		return super.keyDown(keycode, time);
	}

	protected boolean navigationClick(int i, int j) {
		popErrorScreen();
		return super.navigationClick(i, j);
	}

	private void popErrorScreen() {
		UiApplication.getUiApplication().popScreen(this);
	}

}